package com.xyyl.patient.service.common;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.xyyl.patient.core.util.StringUtils;
import com.xyyl.patient.mapper.base.SysConfigMapper;
import com.xyyl.patient.service.base.SysConfigService;

/**
 * @projectName:xyyl-patient-service
 * @ClassName: SysConfigServiceImp
 * @Description:系統配置Service
 * @author chens
 * @date 2017年9月29日
 *
*/
@Service("sysConfigService")
public class SysConfigServiceImpl implements SysConfigService {
	
  private Logger logger=Logger.getLogger(getClass());
  
	@Autowired
	private SysConfigMapper sysConfigMapper;
	
	@Override
	public String getConfigValue(String key, String defaultValue) {
		String value = sysConfigMapper.queryByKey(key);
		if(StringUtils.isEmpty(value)){
			return defaultValue;
		}
		return value;
	}
	
	@Override
	public <T> T getConfigObject(String key, Class<T> clazz) {
		String value = getConfigValue(key, null);
		if(StringUtils.isEmpty(value)){
			return JSON.parseObject(value, clazz);
		}
		try {
			return clazz.newInstance();
		} catch (Exception e) {
			logger.error("获取参数值失败:"+e);
			return null;
		}
	}

}
